package com.neusoft.neuiotms.dcam.fixed.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.bizcore.web.dto.result.PageResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultListDTO;
import com.neusoft.bizcore.web.support.Searchable;
import com.neusoft.neuiotms.dcam.fixed.dto.InventoryResultDTO;
import com.neusoft.neuiotms.dcam.fixed.model.enums.InventoryDutyResultStatus;
import com.neusoft.neuiotms.dcam.fixed.service.InventoryResultService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "盘点结果管理")
@RestController
@RequestMapping(value = "/api/w/fixed/inventory/results")
public class InventoryResultController {

    @Autowired
    private InventoryResultService inventoryDutyResultService;

    @ApiOperation("查询所有盘点结果")
    @GetMapping
    public ResultListDTO<InventoryResultDTO> index(final Searchable searchable) {
        final List<InventoryResultDTO> DTOs = this.inventoryDutyResultService.findAll(searchable);
        final ResultListDTO<InventoryResultDTO> result = ResultListDTO.success(DTOs);
        return result;
    }

    @ApiOperation("分页查询所有盘点结果")
    @GetMapping("/p")
    public PageResultDTO<InventoryResultDTO> search(final Pageable pageable, final Searchable searchable) {
        final Page<InventoryResultDTO> list = this.inventoryDutyResultService.search(pageable, searchable);
        return PageResultDTO.success(list);
    }

    @ApiOperation("增加盘盈数据")
    @PostMapping
    public ResultDTO<InventoryResultDTO> create(@RequestBody final InventoryResultDTO dto) {
        final InventoryResultDTO result = this.inventoryDutyResultService.create(dto);
        return ResultDTO.success(result);
    }

    @ApiOperation("盘点结果详情")
    @GetMapping("/{id}")
    public ResultDTO<InventoryResultDTO> details(@PathVariable final Long id) {
        final InventoryResultDTO dto = this.inventoryDutyResultService.details(id);
        return ResultDTO.success(dto);
    }

    @ApiOperation("修改盘点结果")
    @PutMapping("/{id}")
    public ResultDTO<InventoryResultDTO> update(@PathVariable final Long id,
            @RequestBody final InventoryResultDTO dto) {
        final InventoryResultDTO result = this.inventoryDutyResultService.update(id, dto);
        return ResultDTO.success(result);
    }

    @ApiOperation("修改盘点结果状态")
    @PutMapping("/{id}/{status}")
    public ResultDTO<Void> updateStatus(@PathVariable final Long id,
            @PathVariable final InventoryDutyResultStatus status) {
        this.inventoryDutyResultService.updateStatus(id, status);
        return ResultDTO.success();
    }

    @ApiOperation("删除盘盈数据")
    @DeleteMapping("/{id}")
    public ResultDTO<Void> delete(@PathVariable final Long id) {
        this.inventoryDutyResultService.delete(id);
        return ResultDTO.success();
    }
}
